package com.lanp.native_test.ExecutorsRun.CustomTheadExecutor;

import com.sun.scenario.DelayedRunnable;
import org.apache.commons.lang3.RandomStringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

public class TestDelayRunnable implements Runnable, Delayed {
    /**
     * 几点执行
     */
    private long delayTime;

    public TestDelayRunnable(long delayTime) {
        this.delayTime = delayTime;
    }

    @Override
    public long getDelay(TimeUnit unit) {
        return delayTime - System.currentTimeMillis();
    }

    @Override
    public int compareTo(Delayed o) {
        return 0;
    }

    @Override
    public void run() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        Date nowDate = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(sdf.format(nowDate) + "   " + this.delayTime + "-延时时间:" + RandomStringUtils.randomAlphabetic(10));
    }


}
